<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>权限分配</title>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        body {
            margin:0;
            padding:0;
            border:0;
            width:100%;
            height:100%;
            overflow:hidden;
        }
    </style>
</head>
<body>
<div class="mini-toolbar" style="padding:2px;">
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="onOk()">保存</a>
    <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()">关闭</a>
</div>
<div class="mini-fit" style="margin-top: 10px;margin-left: 10px">
    <ul id="tree1" class="mini-tree" style="width:100%;height:100%;" ajaxType="get"
        showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false"
        showCheckBox="true" allowSelect="false" enableHotTrack="false" autoCheckParent="true"
    >
    </ul>
</div>
<input name="id" class="mini-hidden" value="" />
</body>
<script type="text/javascript">
    mini.parse();
    var tree = mini.get("tree1");

    //标准方法接口定义
    function SetData(data) {
        //跨页面传递的数据对象，克隆后才可以安全使用
        data = mini.clone(data);
        var roleid = data.id;
        mini.getByName("id").setValue(roleid);
        var url = '/role/resource/tree?roleid=' + roleid;
        tree.load(url);
    }

    function GetData() {
        var nodes = tree.getCheckedNodes();
        var ids = [], texts = [];
        for (var i = 0, l = nodes.length; i < l; i++) {
            var node = nodes[i];
            ids.push(node.id);
            texts.push(node.text);
        }
        var data = {};
        data.id = ids.join(",");
        data.text = texts.join(",");
        return data;
    }

    function onOk() {
        var node = tree.getSelectedNode();
        if (node && tree.isLeaf(node) == false) {
            alert("不能选中父节点");
            return;
        }
        var data = GetData();
        data = mini.clone(data);
        var roleid = mini.getByName("id").getValue();
        var url = "/role/resource";
        var type = "POST";
        var dataType = "json";
        var parms = {resids: data.id, roleid: roleid};
        var callback = function () {
            mini.alert("保存成功", "成功", window.CloseOwnerWindow);
        };
        commonAjax(url, type, dataType, parms, null, callback);
    }
</script>
</html>